home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / file-tra / fsp-2.7 / fsp-2 / fsp / server / filecache.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-21  |  2.4 KB  |  87 lines

  1. /* FILECACHE.C
  2.  * Routines to perform file-caching with VMS-FSP V2.6.5jt
  3.  *
  4.  * 05-MAR-93 First Version <S.A.Pechler@bdk.tue.nl>
  5.  * Merged into standard distribution on Mar 10 by jtraub@cs.cmu.edu
  6.  */
  7.  
  8. #include "tweak.h"
  9. #include "server_def.h"
  10. #include "s_extern.h"
  11.  
  12. /* CLEAR_CACHE
  13.  * clears all entries of the file_cache to zero, 
  14.  * points cache_pointer to last empty cache-entry
  15.  */
  16. void clear_cache PROTO2(FPCACHE *, fpcache, FPCACHE **, cache_p)
  17. {
  18.   register int i;
  19.     
  20. #ifdef DEBUG
  21.   printf("clear_cache: delete %d entries\n",FSP_FILE_CACHE);
  22. #endif
  23.   for (i=0;i<=FSP_FILE_CACHE;i++) {
  24.     fpcache[i].fp=0;
  25.     fpcache[i].filename[0]=0;
  26.     fpcache[i].inet_num=0;
  27.     fpcache[i].port_num=0;
  28.   }
  29.   *cache_p= &fpcache[FSP_FILE_CACHE];
  30. }
  31.  
  32. /* FIND_CACHE
  33.  * searches for an entry in the file-cache.
  34.  * returns pointer to entry if found, 0 otherwise.
  35.  */
  36. FPCACHE *find_cache PROTO4(FPCACHE *, fpcache, unsigned short, port_num,
  37.                unsigned long, inet_num, char *, fname)
  38. {
  39.   register int i=FSP_FILE_CACHE;
  40. #ifdef DEBUG
  41.   printf("find_cache: searching for %s:\n",fname);
  42. #endif
  43.   while (i>=0) { /* search for file in cache */
  44.     if (port_num==fpcache[i].port_num && inet_num==fpcache[i].inet_num &&
  45.     !strcmp(fname,fpcache[i].filename))
  46.       /* file found in cache, return cache-pointer */
  47.       return((FPCACHE *)&fpcache[i]);
  48.     i--;
  49.   }
  50.   return((FPCACHE *)0);
  51. }
  52.  
  53. /* DELETE_CACHE
  54.  * deletes current entry from the filecache (file will be closed).
  55.  */
  56. void delete_cache PROTO1(FPCACHE *, cache_p)
  57. {
  58. #ifdef DEBUG
  59.   if (dbug) printf("delete_cache: deleting ptr:%d\n",cache_p);
  60. #endif
  61.   if (cache_p->fp) {
  62.     fclose(cache_p->fp); /* close file */
  63.     cache_p->fp=0;       /* mark entry as being emtpy */
  64.     cache_p->port_num = 0;
  65.     cache_p->inet_num = 0;
  66.     cache_p->filename[0]=0;
  67.   }
  68. }
  69.  
  70. /* ADD_CACHE
  71.  * Adds an entry to the filecache. Returns pointer to next empty
  72.  * entry.
  73.  */
  74. FPCACHE *add_cache PROTO6(FPCACHE *, fpcache, FPCACHE *, cache_p, 
  75.               unsigned short,  port_num, unsigned long, inet_num,
  76.               char *, fname, FILE *, fp)
  77. {
  78.   cache_p->fp= fp;                 /* add filepointer */
  79.   strcpy(cache_p->filename,fname); /* add filename */
  80.   cache_p->inet_num=inet_num;      /* add IP address */
  81.   cache_p->port_num=port_num;      /* add portnumber */
  82.   
  83.   /* return pointer to next cache-entry */
  84.   if (cache_p<=fpcache) return((FPCACHE *)&fpcache[FSP_FILE_CACHE]);
  85.   else return(cache_p-1);
  86. }
  87.